/*****************************************************
Copyright (C) 2020. All rights reserved.
File name     ：TestMain.c
Version       ：v1.0
Author        ：zhengqijun
Date          ：2020-05-07
Function List ：
Description   ：main function
******************************************************/

#include <stdio.h>  // for printf
#include "RedBlackTree.h"

// main function
int main(void) {
    RedBlackTree T = NULL;
    ElementType A[] = {10, 85, 15, 70, 20, 60, 30, 50, 65, 80, 90, 40, 5, 55, 45};
    int size;
    int i;

    T = Initialize();
    T = MakeEmpty(T);

    if (IsEmpty(T)) {
        printf("RedBlackTree is empty!\n");
    } else {
        printf("RedBlackTree is not empty!\n");
    }

    {  /* Insert */
        size = sizeof(A) / sizeof(ElementType);
        for (i = 0; i < size; ++i) {
            T = Insert(A[i], T);
        }
    }

    printf("Insert red black tree: [ ");
    for (i = 0; i < size; ++i) {
        printf("%d ", A[i]);
    }
    printf("]\n");

    printf("Print inserted red black tree:\n");
    PrintTree(T, 0);
    printf("\n");

    if (IsEmpty(T)) {
        printf("RedBlackTree is empty!\n");
    } else {
        printf("RedBlackTree is not empty!\n");
    }

    printf("The preorder traversal of red black tree is: [ ");
    PreorderTraversal(T);
    printf("]\n");

    printf("The inorder traversal of red black tree is: [ ");
    InorderTraversal(T);
    printf("]\n");

    printf("The postorder traversal of red black tree is: [ ");
    PostorderTraversal(T);
    printf("]\n");

    printf("The levelorder traversal of red black tree is: [ ");
    LevelorderTraversal(T);
    printf("]\n");

    printf("Min is %d in red black tree!\n", Retrieve(FindMin(T)));
    printf("Max is %d in red black tree!\n", Retrieve(FindMax(T)));

    if (Retrieve(Find(80, T)) == 80) {
        printf("Find element 80 in red black tree!\n");
    } else {
        printf("Can not find element 80 in red black tree!\n");
    }

    if (Retrieve(Find(63, T)) == 63) {
        printf("Find element 63 in red black tree!\n");
    } else {
        printf("Can not find element 63 in red black tree!\n");
    }

    printf("Remove element 30 in red black tree!\n");
    T = Remove(30, T);

    printf("Print RedBlackTree:\n");
    PrintTree(T, 0);
    printf("\n");

    printf("Remove element 60 in red black tree!\n");
    T = Remove(60, T);

    printf("Print RedBlackTree:\n");
    PrintTree(T, 0);
    printf("\n");

    Destroy(T);

    return 0;
}

// EOF

